//: net/mindview/util/ContainerMethodDifferences.java
package t4j.net.mindview.util;

import java.lang.reflect.*;
import java.util.*;

public class ContainerMethodDifferences {
 
	static Set<String> methodSet(Class<?> type){
		
		Set<String> result = new TreeSet<String>();
		
		for(Method m : type.getMethods())
			
			result.add(m.getName());
		
		return result;
	}
	
	static void interfaces(Class<?> type){
		
		System.out.print("Interfaces in " + type.getSimpleName() + "; ");
	
		List<String> result = new ArrayList<String>();
		
		for(Class<?> c : type.getInterfaces())//获取接口类，因为接口是类，所以也是用Class类型
			
			result.add(c.getSimpleName());
		
		System.out.println(result);
	}
	
	static Set<String> object = methodSet(Object.class);
	
	static{ object.add("clone");}
	
	static void difference(Class<?> superset,Class<?> subset){
		
		System.out.print(superset.getSimpleName() + " extends " + subset.getSimpleName() + ", adds: ");
		
		Set<String> comp = Sets.difference(methodSet(superset), methodSet(subset));
		
		comp.removeAll(object);//Don't show Object methods
		
		System.out.println(comp);
		
		interfaces(superset);
	}
	
	public static void main(String[] args) {
		
		System.out.println("Collection:"   + methodSet(Collection.class));
		
		interfaces(Collection.class);
		
		System.out.println("-------------------------------------------------------");
		
		difference(Set.class, Collection.class);
		System.out.println("-------------------------------------------------------");
		
		
		difference(HashSet.class, Set.class);
		System.out.println("-------------------------------------------------------");
		
	
		difference(LinkedHashSet.class, HashSet.class);
		System.out.println("-------------------------------------------------------");
		
	
		difference(TreeSet.class, Set.class);
		System.out.println("-------------------------------------------------------");
		

		difference(List.class, Collection.class);
		System.out.println("-------------------------------------------------------");
		

		difference(ArrayList.class, List.class);
		System.out.println("-------------------------------------------------------");
		

		difference(LinkedList.class, List.class);
		System.out.println("-------------------------------------------------------");
		

		difference(Queue.class,Collection.class);
		System.out.println("-------------------------------------------------------");
		

		difference(PriorityQueue.class, Queue.class);
		System.out.println("-------------------------------------------------------");
		

		System.out.println("Map: " + methodSet(Map.class));
		
		difference(HashMap.class,Map.class);
		System.out.println("-------------------------------------------------------");
		

		difference(LinkedHashMap.class,HashMap.class);
		System.out.println("-------------------------------------------------------");
		

		difference(SortedMap.class,Map.class);
		System.out.println("-------------------------------------------------------");
		

		difference(TreeMap.class,Map.class);
		
	}
} ///:~
